<?php

if (!defined('BASEPATH'))
	exit('No direct script access allowed');

define("EMPTY", " - ");
class Report extends CI_Controller {

	//Doctrine EntityManager
	public $em;

	function __construct() {
		parent::__construct();

		//Not required if you autoload the library
		$this -> load -> library('doctrine');

		//Instantiate a Doctrine Entity Manager
		$this -> em = $this -> doctrine -> em;
		// $conn = $this->em->getConnection();
		//var_dump(models\service\CurrentUser::user());
		if (models\service\CurrentUser::user() == FALSE){
			header('location: ' . base_url());
		}
		
		// $conn->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'varchar');
	}
	
	
	// START Katalog
	public function index() {
		$user = models\service\CurrentUser::user();
		$criteria = array('userId' => $user->getUserId());
		$userProfiles = $this->em->getRepository('\models\entities\UserProfile')->findBy($criteria);
		
		$data['breadcrumb'] = array( array("label" => "Home", "link" => base_url() . "dashboard"),
								 array("label" => "Report", "link" => NULL)
								);
								
		$data['reports'] = $this->em->getRepository('\models\entities\Berkas')->paginateReportTrainingAbsensi();
		$criteria = array('userId' => $user->getUserId());
		$userProfiles = $this->em->getRepository('\models\entities\UserProfile')->findBy($criteria);
		$data['userProfiles'] = $userProfiles;
		$data['user'] = $user;
		$this -> load -> view('report/index', $data);		
	}

	function pdf(){
	     $this->load->helper(array('dompdf', 'file'));
		 
	     // page info here, db calls, etc.     
	     //$data = null;
	     $data['test'] = "test";
	     $html = $this->load->view('report/test', $data, true);
		 //var_dump($html);
		 //die('tests');
	     pdf_create($html, 'filename');
	    /* or
	     $data = pdf_create($html, '', false);
	     write_file('name', $data); */
	     //if you want to write it to disk and/or send it as an attachment    
	}
}

